var e = require("../utils/murmurhash2.js"),
  t = require("../utils/util.js"),
  i = require("../comm/local"),
  n = require("../comm/packet"),
  r = require("../utils/sign.js").default,
  a = require("../../buildConfig").BuildConfig;
module.exports = {
  initReqFeatureObj: function (r, a, s) {
    var p,
      o = t.isEmpty(s[0]) ? "" : s[0],
      u = t.isEmpty(s[1]) ? "" : JSON.stringify(s[1].wifi || s[1]),
      l = t.isEmpty(s[2]) ? "" : JSON.stringify(s[2].beacons || s[2]),
      m = s[3];
    t.isEmpty(m) || t.isEmpty(m.data) || (p = wx.arrayBufferToBase64(m.data));
    var c = s[4],
      y = s[5];
    if (!t.isEmpty(y))
      var d = y.cpu_id,
        h = y.uid;
    var f = s[6];
    t.isEmpty(f) && (f = {});
    var E = i.getUUID(
        i.uidKey(a.salt),
        i.tTokenKey(a.salt),
        i.rTokenKey(a.salt),
      ),
      b = t.isEmpty(r) ? E : r,
      g = {
        1: n.encryptFeature(E, "01303975070694866490574863106155", !0),
        2: t.isEmpty(r) ? "" : r,
        4: t.isEmpty(o.platform) ? "" : o.platform,
        101: t.isEmpty(f.openid) ? "" : f.openid,
        103: t.isEmpty(o.SDKVersion) ? "" : o.SDKVersion,
        104: t.isEmpty(o.brand) ? "" : o.brand,
        105: t.isEmpty(o.model) ? "" : o.model,
        106: t.isEmpty(o.screenHeight)
          ? ""
          : o.screenHeight + "*" + o.screenWidth,
        107: t.isEmpty(o.system) ? "" : o.system,
        108: t.isEmpty(o.language) ? "" : o.language,
        109: t.isEmpty(l)
          ? l
          : n.encryptFeature(l, e.hash32(b + "109", 256), !0),
        110: t.isEmpty(u)
          ? u
          : n.encryptFeature(u, e.hash32(b + "110", 256), !0),
        111: t.isEmpty(o.version) ? "" : o.version,
        112: t.isEmpty(o.setFontSize) ? "" : o.setFontSize,
        113: t.isEmpty(f.avatar) ? "" : f.avatar,
        114: t.isEmpty(f.rawData)
          ? ""
          : n.encryptFeature(f.rawData, e.hash32(b + "114", 256), !0),
        115: "",
        116: t.isEmpty(o.statusBarHeight) ? "" : o.statusBarHeight,
        117: t.isEmpty(o.benchmarkLevel) ? "" : o.benchmarkLevel,
        118:
          Number(o.albumAuthorized) ||
          "0:" +
            Number(o.cameraAuthorized) +
            ":" +
            Number(o.locationAuthorized) +
            ":" +
            Number(o.microphoneAuthorized) +
            ":" +
            Number(o.notificationAuthorized) +
            ":" +
            Number(o.bluetoothEnabled) +
            ":" +
            Number(o.locationEnabled) +
            ":" +
            Number(o.wifiEnabled),
        119: "",
        1e3: t.isEmpty(p)
          ? ""
          : n.encryptFeature(e.hash32(p, 256), e.hash32(b + "1000", 256), !0),
        1001: t.isEmpty(c)
          ? ""
          : n.encryptFeature(e.hash32(c, 256), e.hash32(b + "1001", 256), !0),
        1002: t.isEmpty(d)
          ? ""
          : n.encryptFeature(d, e.hash32(b + "1002", 256), !0),
        1003: t.isEmpty(h)
          ? ""
          : n.encryptFeature(h, e.hash32(b + "1003", 256), !0),
      };
    return (
      0 == a.type ? (g[101] = a.openid || "") : (g[119] = a.openid || ""),
      { featureObj: g, uuid: E }
    );
  },
  initReqConfig: function (e) {
    var i;
    if (e) {
      (i = e).clientInfo ||
        (i.clientInfo = {
          requestSeq: "",
          metaData: "",
          channel: "testclientchannel",
          buildNo: 1,
          version: "",
          lc: "testclientlc",
          extraInfo: "",
          appid: "",
          type: "",
        }),
        null == i.type ? (i.clientInfo.type = 0) : (i.clientInfo.type = i.type),
        i.productInfo ||
          (i.productInfo = { clientVer: "", requestPackageName: "" }),
        null == i.openid || i.openid.length,
        null == i.subappid ||
          0 == i.subappid.length ||
          (i.clientInfo.appid = i.subappid);
      var n = wx.getAccountInfoSync();
      t.isEmpty(n) ||
        t.isEmpty(n.miniProgram) ||
        (i.clientInfo.wx_appid = n.miniProgram.appId);
    } else
      i = {
        productInfo: { clientVer: "", requestPackageName: "" },
        clientInfo: {
          requestSeq: "",
          metaData: "",
          channel: "testclientchannel",
          buildNo: 1,
          version: "",
          lc: "testclientlc",
          extraInfo: "",
          appid: "",
          type: 0,
        },
        openid: "",
      };
    return i;
  },
  initContent: function (e, i, n) {
    var s = Date.now(),
      p = "";
    return (
      t.isEmpty(e.channel) || (p = e.channel),
      t.isEmpty(n) ? (n = { 10: r(s, i) }) : (n[10] = r(s, i)),
      {
        timestamp: s,
        requireType: e.requireType,
        sdkInfo: {
          buildno: a.buildNo,
          sdkver: a.sdkVersion,
          lc: a.lc,
          channel: p,
          platform: 5,
        },
        productInfo: e.productInfo,
        clientInfo: e.clientInfo,
        statisticsInfo: n || null,
        featureObj: i,
      }
    );
  },
};
